FUNCTION_BLOCK LCB_Speed_sToNorm_n 
TITLE = 'LCB_Speed_sToNorm_n'

// This FB uses the transmitted machine parameters and converts a 32-bit speed signal into a scaled 32-bit signal.
//
// Versionshistory:
// 1.0 Ersterstellung R.Enders 

VERSION : '1.0'
AUTHOR  : 'Lenze'
FAMILY  : 'LCB'
NAME : 'SsToNn' // ( 8 Zeichen max.)
KNOW_HOW_PROTECT


VAR_INPUT
    diIn_s        : DINT;
    AxisData      : BLOCK_DB; 
    
END_VAR

VAR_OUTPUT
    diOut_n       : DINT;
    xError        : BOOL;
END_VAR

VAR
   rOut_n     : REAL;
    
   rOut_s               : REAL;
   dwReferenceSpeed     : dword; 
   rReferenceSpeed      : REAL;
      
END_VAR


BEGIN
dwReferenceSpeed:= AxisData.dd16 ;
rReferenceSpeed:= DWORD_TO_REAL (dwReferenceSpeed);

    rOut_n := ( DINT_TO_REAL(diIn_s) / rReferenceSpeed *  1073741824.0);

    rOut_n := LIMIT(MN:=-2147483568.0,IN:=rOut_n,MX:=2147483568.0);
    diOut_n := REAL_TO_DINT(rOut_n);
    IF rReferenceSpeed <= 0 THEN   xError := True;
    ELSE xError := False;
    END_IF;

      
END_FUNCTION_BLOCK




    
